#include "SypEngine.h"

#ifdef CHECKMEM
#include "mmgr.h"
#endif
namespace Syp
{

void ErrorLogger::initialise()
{
	if(!err)
	{//if NULL
		err = new OutputStream;
	}
	if(!err->is_open())
	{//if file is not open, open it
		err->open("Log.txt");
	}
	(*err)<<"Syp Engine v"<<SypEngine::getVersion()<<std::endl;
}

OutputStream& ErrorLogger::getLogger()
{	
	assert(err && "ErrorLogger has not been intialised");
	return (*err);//return reference to Logger
}

void ErrorLogger::release()
{
	//if object exists
	if(err)
	{
		(*err)<<"Log File properly released"<<std::endl;
	if(err->is_open())//if file is open, close it
		err->close();
	delete err;//delete the object
	err = NULL;
	}
}

void ErrorLogger::showError(const String& error)
{
	ErrorLogger::getLogger()<<"ERROR : "<<error<<std::endl;
}
OutputStream* ErrorLogger::err = 0;
}
